import torch.nn as nn
import torch.nn.functional as F


class CnnBest(nn.Module):
    def __init__(self):
        super(CnnBest, self).__init__()
        self.conv1 = nn.Conv1d(1, 64, 11, stride=1, padding=5)
        self.average_pool1 = nn.AvgPool1d(2, stride=2)
        self.conv2 = nn.Conv1d(64, 128, 11, stride=1, padding=5)
        self.average_pool2 = nn.AvgPool1d(2, stride=2)
        self.conv3 = nn.Conv1d(128, 256, 11, stride=1, padding=5)
        self.average_pool3 = nn.AvgPool1d(2, stride=2)
        self.conv4 = nn.Conv1d(256, 512, 11, stride=1, padding=5)
        self.average_pool4 = nn.AvgPool1d(2, stride=2)
        self.conv5 = nn.Conv1d(512, 512, 11, stride=1, padding=5)
        self.average_pool5 = nn.AvgPool1d(2, stride=2)
        self.flatten = nn.Flatten()
        self.fc1 = nn.Linear(512 * 21, 4096)
        self.fc2 = nn.Linear(4096, 4096)
        self.fc3 = nn.Linear(4096, 256)

    def forward(self, x):
        x = x.view(len(x), 1, 700)
        x = F.relu(self.conv1(x))
        x = self.average_pool1(x)
        x = F.relu(self.conv2(x))
        x = self.average_pool2(x)
        x = F.relu(self.conv3(x))
        x = self.average_pool3(x)
        x = F.relu(self.conv4(x))
        x = self.average_pool4(x)
        x = F.relu(self.conv5(x))
        x = self.average_pool5(x)
        x = self.flatten(x)
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return x
